package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderSubmitVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    //插入订单数据
    void insert(Orders orders);

    //根据订单号和用户id查询订单
    @Select("select * from orders where number = #{orderNumber} and user_id = #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    //模仿小程序支付成功后，修改订单状态
    @Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{check_out_time} where id = #{id}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime check_out_time, Long id);
    //修改订单信息
    void update(Orders orders);
    //分页查询历史订单
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    //根据订单id查询订单
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    //各个状态的订单数量统计
    @Select("select count(*) from orders where status = #{Status}")
    Integer countByStatus(Integer Status);
    //定时任务根据状态和下单时间查询订单
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getByStatusandtime(Integer status, LocalDateTime orderTime);

    //根据动态条件统计营业额数据
    Double sumByMap(Map map);

    //根据动态条件统计订单数量
    Integer ordersByMap(Map map);

    //统计指定时间区间内的销量排名前10
    List<GoodsSalesDTO> getGoodsSales(LocalDateTime begin, LocalDateTime end);
}
